

class HtmlOutputer(object):
    def __init__(self):
        self.datas = []

    def collect_data(self,data):     #收集数据
        if data is None:
            return
        self.datas.append(data)


    def output_html(self):      #将收集到的数据输出到html文件中
        fout = open('output.html','w',encoding='utf-8')

        fout.write("<html>")
        fout.write("<meta charset=\"utf-8\" /> ")
        fout.write("<body>")
        fout.write("<table>")


        for data in self.datas:

            fout.write("<tr>")
            fout.write("<td>%s</td>" % str(data['url'].encode('utf-8'), 'utf-8'))
            fout.write("<td>%s</td>" % str(data['title'].encode('utf-8'), 'utf-8'))
            fout.write("<td>%s</td>" % str(data['summary'].encode('utf-8'),'utf-8'))
            fout.write("</tr>")
            

        fout.write("</table>")
        fout.write("</body>")
        fout.write("</html>")
        fout.close()
